package com.ruoyi.puyu.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.puyu.domain.PuyuPointsRule;
import com.ruoyi.puyu.service.IPuyuPointsRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 积分规则Controller
 * 
 * @author wusongwen
 * @date 2024-12-25
 */
@RestController
@RequestMapping("/puyu/rule")
public class PuyuPointsRuleController extends BaseController
{
    @Autowired
    private IPuyuPointsRuleService puyuPointsRuleService;

    /**
     * 查询积分规则列表
     */
    @PreAuthorize("@ss.hasPermi('puyu:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(PuyuPointsRule puyuPointsRule)
    {
        startPage();
        List<PuyuPointsRule> list = puyuPointsRuleService.selectPuyuPointsRuleList(puyuPointsRule);
        return getDataTable(list);
    }

    /**
     * 导出积分规则列表
     */
    @PreAuthorize("@ss.hasPermi('puyu:rule:export')")
    @Log(title = "积分规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PuyuPointsRule puyuPointsRule)
    {
        List<PuyuPointsRule> list = puyuPointsRuleService.selectPuyuPointsRuleList(puyuPointsRule);
        ExcelUtil<PuyuPointsRule> util = new ExcelUtil<PuyuPointsRule>(PuyuPointsRule.class);
        util.exportExcel(response, list, "积分规则数据");
    }

    /**
     * 获取积分规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('puyu:rule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(puyuPointsRuleService.selectPuyuPointsRuleByRuleId(ruleId));
    }

    /**
     * 获取积分规则详细信息
     */
    @GetMapping("/last")
    public AjaxResult get()
    {
        return success(puyuPointsRuleService.selectPuyuPointsRuleLatest());
    }

    /**
     * 新增积分规则
     */
    @PreAuthorize("@ss.hasPermi('puyu:rule:add')")
    @Log(title = "积分规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PuyuPointsRule puyuPointsRule)
    {
        return toAjax(puyuPointsRuleService.insertPuyuPointsRule(puyuPointsRule));
    }

    /**
     * 修改积分规则
     */
    @PreAuthorize("@ss.hasPermi('puyu:rule:edit')")
    @Log(title = "积分规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PuyuPointsRule puyuPointsRule)
    {
        return toAjax(puyuPointsRuleService.updatePuyuPointsRule(puyuPointsRule));
    }

    /**
     * 删除积分规则
     */
    @PreAuthorize("@ss.hasPermi('puyu:rule:remove')")
    @Log(title = "积分规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(puyuPointsRuleService.deletePuyuPointsRuleByRuleIds(ruleIds));
    }
}
